473,416 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Dynamically populating a DropDownList, AutoPostback and JavaScript error

112 100+
hello,

i am trying to create a request form using asp.net where when a user selects a checkbox, a dropdown should appear dynamically. I have seen few java-scripts in web, but I was wondering if I can achieve this without java-script.

I tried to make the control invisible(<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" Visible="False">) and in the onselectedindexchanged event, tried to make the invisible property to true. But it did not help me.
Also, I was trying to use postback for the page when a checkbox is selected(asp:CheckBoxList ID="chckbx" runat="server" AutoPostBack="true" onselectedindexchanged="chckbx_SelectedIndexChange d") and it throws me an error in IE saying the object does not support this property.


Can somebody please help me with this. Thanks in advance.
Dec 7 '09 #1
27 7867
Frinavale
9,735 Expert Mod 8TB
Before you continue please take a look at this article on:
How to use dynamic controls in ASP.NET.

-Frinny
Dec 7 '09 #2
user1980
112 100+
thank you for the reply.

I am able to understand the example in the link but could not really put it into working for my scenario.
Dec 7 '09 #3
Frinavale
9,735 Expert Mod 8TB
Ok, in your scenario you need to do this when the user checks a checkbox.
I'm assuming that you need to populate the drop down list with items depending on what the user has checked.

This is not dynamically creating a control.

What you need to do is dynamically populate the drop down list.

What do you have currently that we can use as a starting point?

-Frinny
(PS please post code in code tags)
Dec 7 '09 #4
user1980
112 100+
Yes, I have to populate the dropdown based on the selection of checkbox.

Here is my information. I have four sources of information as checkboxes, newspapers,web,employee and others. Now when a user checks newspapers, the dropdown must populate, tribune,WSjournal,PJ star.

And one more thing is if I put the autopostback ppty for checkbox to true, it throws me an error. This should be something very basic, am I missing something?
Thanks for all your help.
Dec 7 '09 #5
Frinavale
9,735 Expert Mod 8TB
Lets fix the error because you need to set the checkBoxList's autopostback=true.
Please post the error details.

-Frinny
Dec 7 '09 #6
user1980
112 100+
the error appears only in IE, as a script error. I mean the page loads normally but on the left hand bottom corner, it says there is an error on the page. When i click on it, it tells me the the object does not support this property or method.
When I try to debug the page without the autopostback property, it does not display any error.
Dec 7 '09 #7
Frinavale
9,735 Expert Mod 8TB
Do you have any additional JavaScript on the page?

-Frinny
Dec 7 '09 #8
user1980
112 100+
yes, a one line javascript to open a pop-up window.
Dec 7 '09 #9
Frinavale
9,735 Expert Mod 8TB
Post that code please.

-Frinny
Dec 7 '09 #10
user1980
112 100+
Expand|Select|Wrap|Line Numbers
  1. function window_open()
  2.       {
  3.        window.open("Codes.aspx","","menubar=no,status=no,scrollbars=yes,resizable=yes,toolbar=no,top=180,left=250,width=750,height=600");
  4.       }
the ap.net control that calls it,
Expand|Select|Wrap|Line Numbers
  1. <asp:Button runat="server" ID="btnlookup" Text="Code" OnClientClick="window_open()" CausesValidation="false" Width="90px" />
Dec 7 '09 #11
Frinavale
9,735 Expert Mod 8TB
I don't see anything wrong with this JavaScript.
I'm going to ask that a JavaScript expert take a look at this.

Does this problem prevent your code from being executed?
If so, could you remove it while we are fixing your current problem with dynamically populating the DropDownList?

-Frinny
Dec 7 '09 #12
Dormilich
8,658 Expert Mod 8TB
I'm going to ask that a JavaScript expert take a look at this.
I can’t find anything wrong, works as expected when inserted in plain text HTML.
Dec 7 '09 #13
user1980
112 100+
my page executes normally. but I just wanted to get rid of the error and also wanted to postback the page when I check the checkbox.
Dec 7 '09 #14
Frinavale
9,735 Expert Mod 8TB
Well enable autopostback for the checkbox.
Put a break point on the method that handles the event and run the application.
Do you hit the break point?

-Frinny
Dec 7 '09 #15
user1980
112 100+
ah..it does not hit the breakpoint. and the script error is displayed only when I try to check the checkbox, not when the page loads.
Dec 7 '09 #16
Frinavale
9,735 Expert Mod 8TB
Okay, it sounds like the JavaScript that preforms the AutoPostback is not working.

I don't know why this would be the case. The only thing that I can think of is that your JavaScript is somehow invalid (maybe you didn't close the <script> tag?) But your JavaScript looks fine.

Try removing your JavaScript from the page.
Do you get the same error?

What web browser are you using? What version is it?

Are you using Ajax?
If so are you using any Ajax enabled controls?
These may be causing a problem...


-Frinny
Dec 7 '09 #17
user1980
112 100+
Hi Frinny

Thank you for your quick responses.

I did try to remove the javascript from the page. it still gives me the error. I am currently using IE7 and I do not have any ajax controls.
I did try to create a new checkbox list and even that gives me the same error.

I created a new page and could figure out the how to create a dropdown when a checkbox is selected. It works fine. But my original page still has the error for the autopostback.

Your help is greatly appreciated.
Thank you...
Dec 7 '09 #18
Frinavale
9,735 Expert Mod 8TB
It's too bad that you were having such a hard time with your original page.
At least the error isn't happening on your new aspx page.

So, in the method that handles the AutoPostback for the CheckBoxList (list??) you need to create list items for your DropDownList based on what was checked/selected.

(I'm not sure what language you're using.)

There are two ways to do this. You can create generate ListItem objects and add them to your DropDownList's "Items" property. Or you can bind your DropDownList to a data source.

-Frinny
Dec 7 '09 #19
user1980
112 100+
yeah. I did use the items property to make my dropdowns work and it works fine, but still could not figure out what is wrong with original page.

Anyway thanks a lot for your help and support.
Dec 7 '09 #20
Frinavale
9,735 Expert Mod 8TB
Ah, sorry I miss-read your response.
You have figured out how to dynamically populate your DropDownList.
Contrats!

:)

I have no idea what is wrong with your page.
I can't see you page so....I'm kind of in the dark here.

The only reasons that I can think of is that there is some sort of invalid JavaScript or Ajax on the page that is breaking the code that normally preforms the AutoPostback.

Stuff like not closing the script tag or leaving out a curly brace ("}") or something.

If you want to debug your original page, and you don't want to move your code into the new page, then (...I think I'm going to regret asking for this but...) please post the entire ASPX page code. **winces**

-Frinny
Dec 7 '09 #21
user1980
112 100+
Thank you.

But I am afraid I wont be able to post the aspx code as it has many fields that are pulled from a database.
Anyway, I will try to move my code once I figure out a small issue that i have with my new page.

My new issue, as mentioned earlier I have a checkbox list. But checking only one box should enable the dropdown.
For example,
  • Web
  • Employees
  • Newspaper
  • Other

As it is a checkbox list, a user can select any number of checkboxes. BUt my dropdwon should be enabled only when newspapers is checked.I see that whenever I select more than two checkboxes, the CheckBoxList1.SelectedValue still has only one value. For example a user selects both web and newspaper, but the dropdown is not enabled as CheckBoxList1.SelectedValue is Web.
In my CheckBoxList1_SelectedIndexChanged, I am using
Expand|Select|Wrap|Line Numbers
  1. if (CheckBoxList1.SelectedValue == "NewsPaper"){//enable dropdown}
Am I missing a logic here or is there any way to collect all the values that are checked
Any help would be greatly appreciated.
Please let me know if I am not clear.
Dec 7 '09 #22
Frinavale
9,735 Expert Mod 8TB
Loop through each item in the CheckBoxList and check if it is "NewsPaper" and if it is selected.

The thing is that the CheckBoxList is going to post back every time a check box is checked within it. Make sure you check to see if the DropDownList is already populated.

-Frinny
Dec 8 '09 #23
user1980
112 100+
Hello Frinny

Thanks for all the help. I have accomplished all the required functionality. But still my script error exists, I tried to transfer my original page code to a new page...and again the script error pops up...still struggling to find out the cause.
Dec 8 '09 #24
Frinavale
9,735 Expert Mod 8TB
Wish I could help but I'm in the dark here.
Can't see what you're doing.

-Frinny
Dec 8 '09 #25
user1980
112 100+
yeah..I can understand. Wish I could share the .aspx file.
Anyway, I am debugging the code line by line...and trying to find my luck

Thank you..
Dec 8 '09 #26
user1980
112 100+
Hurray, my code is working.
I had a sumbit button in my page with id='submit' and I did change the small letter 's' to capital letter 'S' and it working like a charm..
It was a silly thing but dont know why it caused the problem. Have found this solution online after hours of searching.
Thought this could help someone like me.
Dec 8 '09 #27
Frinavale
9,735 Expert Mod 8TB
It's strange that this would cause a problem with JavaScript.
Regardless I'm glad you solved your problem :)

-Frinny
Dec 9 '09 #28

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
0
by: theo | last post by:
Hello..I have a similar issue as yesterday but the situation has slightly changed so perhaps someone can shed some more light on the issue... Program flow - load file,extract xml text tags from...
0
by: Thomas Due | last post by:
Hello, I am in the process of making my asp.net form to validate as xhtml 1.0 strict. So far I am doing well, but now I have a problem. The problem concerns specifically DropDownList and...
7
by: Daniel | last post by:
Is there any other way can override this event, like javascript onchange added to the attribute of this dropdownlist? Thanks
5
by: bryanp10 | last post by:
I have a page that is almost entirely dynamically created. Textboxes and checkbox are working fine, firing events, and persistent their state. DropDownList is giving me a major headache. All...
1
by: Wim | last post by:
Hi Everyone, I'm trying to speed up a Asp.net 1.1 applications' performance. The application needs to run in an environment with little bandwith and therefore pagesizes and roundtrip times shoud...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
0
by: eurorscg | last post by:
Hi, i have this dropdownlist that breaks xhtml w3c validation.because it generates a select tag with a javascript property. this only happens when autopostback is set to true. so the the...
0
by: asmx126453 | last post by:
Hey mensen I am having some big troubles here i tryd solving it myself with internet for 2 days but i kind fix it. Its about this i have a DotNet project that alrydi is online and working for...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.